<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>从给定的 GD2 文件或 URL 中的部分新建一图像</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.imagecreatefromgd2part" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecreatefromgd2part</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">imagecreatefromgd2part</span> &mdash; <span class="dc-title">从给定的 GD2 文件或 URL 中的部分新建一图像</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecreatefromgd2part-description">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>imagecreatefromgd2part</strong></span>
     ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
    , <span class="methodparam"><span class="type">int</span> <code class="parameter">$srcX</code></span>
    , <span class="methodparam"><span class="type">int</span> <code class="parameter">$srcY</code></span>
    , <span class="methodparam"><span class="type">int</span> <code class="parameter">$width</code></span>
    , <span class="methodparam"><span class="type">int</span> <code class="parameter">$height</code></span>
    ) : <span class="type">resource</span></div>

   <p class="para rdfs-comment">
    Create a new image from a given part of GD2 file or URL.
   </p>
   <div class="tip"><strong class="tip">Tip</strong><p class="simpara">如已启用<a href="filesystem.configuration.html#ini.allow_url_fopen" class="link">fopen 包装器</a>，在此函数中， URL 可作为文件名。关于如何指定文件名详见 <span class="function"><a href="fopen.html" class="function">fopen()</a></span>。各种
wapper 的不同功能请参见 <a href="wrappers.html" class="xref">支持的协议和封装协议</a>，注意其用法及其可提供的预定义变量。</p></div>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecreatefromgd2part-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       Path to the GD2 image.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">srcX</code></dt>

     <dd>

      <p class="para">
       x-coordinate of source point.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">srcY</code></dt>

     <dd>

      <p class="para">
       y-coordinate of source point.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">width</code></dt>

     <dd>

      <p class="para">源图象的宽度。</p>
     </dd>

    
    
     <dt>
<code class="parameter">height</code></dt>

     <dd>

      <p class="para">源图象的高度。</p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecreatefromgd2part-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">成功后返回图象资源,失败后返回 <strong><code>FALSE</code></strong> 。</p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imagecreatefromgd2part-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3679">
    <p><strong>Example #1 <span class="function"><strong>imagecreatefromgd2part()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;For&nbsp;this&nbsp;example&nbsp;we&nbsp;need&nbsp;the&nbsp;image&nbsp;size&nbsp;before<br /></span><span style="color: #0000BB">$image&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #DD0000">'./test.gd2'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;the&nbsp;image&nbsp;instance&nbsp;now&nbsp;we&nbsp;got&nbsp;the&nbsp;image&nbsp;<br />//&nbsp;sizes<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatefromgd2part</span><span style="color: #007700">(</span><span style="color: #DD0000">'./test.gd2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;(</span><span style="color: #0000BB">$image</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">,&nbsp;(</span><span style="color: #0000BB">$image</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Do&nbsp;an&nbsp;image&nbsp;operation,&nbsp;in&nbsp;this&nbsp;case&nbsp;we&nbsp;emboss&nbsp;the&nbsp;<br />//&nbsp;image&nbsp;if&nbsp;PHP&nbsp;5+<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">function_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'imagefilter'</span><span style="color: #007700">))<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">imagefilter</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IMG_FILTER_EMBOSS</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Save&nbsp;optimized&nbsp;image<br /></span><span style="color: #0000BB">imagegd2</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'./test_emboss.gd2'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imagecreatefromgd2part-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本)。</span></p></blockquote>
  <div class="warning"><strong class="warning">Warning</strong><p class="para">Windows 版本的 PHP 在 4.3.0
版之前不支持通过此函数访问远程文件，即使已经启用 <a href="filesystem.configuration.html#ini.allow-url-fopen" class="link">allow_url_fopen</a>.
</p></div>
 </div>

</div></div></div></body></html>